/*
雀九非当庄模式游戏场景主要逻辑;
*/
var gameData = require("gameData");
var confige = require("confige");
// var sanKungLogic = require("sanKungLogic");
var PaiGowLogic = require("PaiGowLogic");
cc.Class({
    extends: cc.Component,

    properties: {
    },
    //场景加载完毕后的第一次初始化;初始化场景主要的几个节点和状态参数,加载资源;
    onLoad: function () {
        window.clientGlobal.loadingNode.hideLayer();
        this.resNode = this.node.getChildByName("resNode");
        confige.h5RoomID = "0";

        if(cc.sys.platform == cc.sys.IPAD)
            cc.view.setDesignResolutionSize(1280,720,cc.ResolutionPolicy.EXACT_FIT);
        if(cc.sys.platform == cc.sys.MOBILE_BROWSER)
            cc.view.setDesignResolutionSize(1280,790,cc.ResolutionPolicy.EXACT_FIT);
        this.gameBGNode = this.node.getChildByName("gameBgNode").getComponent("gameBgNode");
        this.gameBGNode.onInit();

        this.playerNode = this.node.getChildByName("playerNode");
        this.infoNode = this.node.getChildByName("infoNode");
        this.playerLoadOK = false;
        this.infoLoadOK = false;
        this.doLaterLoad = false;
        this.isSanKung = false;
        
        var self = this;
        self.gameInfoNode = self.infoNode.getChildByName("gameInfoNode").getComponent("gameInfoNode");
        self.gameInfoNode.onInit();
        self.infoLoadOK = true;
        self.gamePlayerNode = self.playerNode.getChildByName("paiGowPlayerNode").getComponent("gamePlayerNode");
        self.gamePlayerNode.onInit();
        self.doLaterLoad = true;
        self.playerLoadOK = true;
        self.loadRes1();
        // self.loadLater();
        // self.startLater();
        
        console.log("gameScene Load!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    },

    start: function () {

    },
    //场景加载完毕后的第二次初始化,在加载完场景需要的牌型、音效等资源后调用;初始化游戏模式,各种功能节点;
    loadLater:function(){
        console.log("loadLater!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        pomelo.clientScene = this;
        confige.curGameScene = this;
        gameData.gameMainScene = this;
        this.gameInfoNode.btn_inviteFriend.active = true;
        this.sceneLoadOver = false;
        this.timeCallFunc = -1;
        this.waitForSettle = false;

        this.winLoseNode = this.node.getChildByName("winLoseNode").getComponent("winLoseNode");
        this.winLoseNode.onInit();
        this.cardMode = confige.roomData.cardMode;
        this.gameMode = confige.roomData.gameMode;
        this.bankerMode = confige.roomData.bankerMode;
        this.betType = {
            "3" : { "1" : true,"5" : true,"10" : true,"15" : true,"20" : true,"repeat" : false,"maxBet" : 20},       //轮庄
            "6" : { "1" : true,"5" : true,"10" : true,"15" : true,"20" : true,"repeat" : false,"maxBet" : 20},       //九点坐庄
            "7" : { "1" : true,"5" : true,"10" : true,"15" : true,"20" : true,"repeat" : true ,"maxBet" : 100},      //无庄（开船）
            "8" : { "1" : true,"2" : true,"3"  : true,"4"  : true,"5"  : true,"repeat" : false,"maxBet" : 5}         //加倍抢庄
        };

        this.time_rob = Math.ceil(confige.roomData.TID_ROB_TIME/1000);
        this.time_betting = Math.ceil(confige.roomData.TID_BETTING/1000);
        this.time_settlement = Math.ceil(confige.roomData.TID_SETTLEMENT/1000);
        
        this.meChair = 0;
        this.curBankerChair = -1;
        if(confige.roomData.bankerMode == 8)
        {
            this.robMaxNumNode = this.gameBGNode.scorePool.getChildByName("robMaxNum");
            this.robMaxNumLabel = this.robMaxNumNode.getComponent("cc.Label");
            this.curRobMaxNum = 0;
        }
        
        this.joinState = confige.roomData.state;
        this.gameBegin = false;     //本房间游戏开始
        this.gameStart = false;     //当前局游戏开始
        this.joinLate = false;

        this.timerItem = this.node.getChildByName("timerItem").getComponent("timerItem");
        this.timerItem.onInit();

        this.allBetNum = 0;
        this.myBetNum = 0;
        
        this.pushBanker = this.node.getChildByName("btn_pushBanker");
        this.unpushBanker = this.node.getChildByName("btn_unPushBanker");
        this.readyBtn = this.node.getChildByName("btn_ready");
        this.robBtnBox = this.node.getChildByName("robBtnBox");

        this.bottomNode = this.node.getChildByName("bottomNode");
        this.mainPlayerNick = this.bottomNode.getChildByName("mainPlayerNode").getChildByName("nick").getComponent("cc.Label");
        this.mainPlayerScore = this.bottomNode.getChildByName("mainPlayerNode").getChildByName("score").getComponent("cc.Label");
        this.mainPlayerHead = this.bottomNode.getChildByName("mainPlayerNode").getChildByName("head").getComponent("cc.Sprite");
        this.mainPlayerNick.string = this.subNameString(confige.userInfo.nickname,6);
        this.mainPlayerScore.string = "0";
        if(confige.meWXHeadFrame != -1)
            this.mainPlayerHead.spriteFrame = confige.meWXHeadFrame;

        this.showCardBtn = this.bottomNode.getChildByName("btnOpenCard")//.getComponent("cc.Button");
        this.moveCardBtn = this.bottomNode.getChildByName("btnMoveCard")//.getComponent("cc.Button");
        this.deactiveShowCardBtn();
        this.betNumList = [1,5,10,15,20];
        this.betBtnList = {};
        for(var i=0;i<5;i++)
            this.betBtnList[i] = this.bottomNode.getChildByName("bet"+i)//.getComponent("cc.Button");;
        if(confige.roomData.bankerMode == 8){
            this.betNumList = [1,2,3,4,5];
            for(var i=0;i<5;i++)
                this.bottomNode.getChildByName("bet"+i).getChildByName("num").getComponent("cc.Label").string = this.betNumList[i];

            this.initBankerRun();
        }
        this.closeBetBtn();
        this.betNumMax = 20;
        
        this.onMoveCard = false;
        this.moveCardLayer = this.node.getChildByName("moveCardLayer").getComponent("moveCardLayer");
        this.moveCardLayer.onInit("bankerMode");
        this.moveCardLayer.parent = this;

        this.gameStatus = this.node.getChildByName("gameStatus");
        this.gameStatusList = {};
        for(var i=1;i<=5;i++)
        {
            this.gameStatusList[i] = this.gameStatus.getChildByName("tips" + i);
        }
        this.addScoreList = {}
        for(var i=0;i<=8;i++)
        {
            this.addScoreList[i] = this.node.getChildByName("playerNode").getChildByName("paiGowPlayerNode").getChildByName("GamePlayer"+i).getChildByName("score")
        }

        this.btnCanSend = true;
    },
    //根据长度截取字符串长度 末尾加...
    subNameString:function(str,isLenght){
        var realLength = 0;
        var len = str.length;
        var subLen = 0;
        for (var i = 0; i < len; i++) {
            var charCode = str.charCodeAt(i);
            if (charCode >= 0 && charCode <= 128) 
               realLength += 1;
            else
               realLength += 2;
            subLen += 1;
            if(realLength >= isLenght)
            {
                break;
            }
        }
        var str1 = "";
        if(realLength < len)
        {
            str1 = str.substring(0,subLen)+ "...";
        }
        else
        {
            str1 = str;
        }
        
        return str1;
    },
    //场景加载完毕后的第二次初始化,在加载完场景需要的牌型、音效等资源后调用;初始化游戏模式,各种功能节点;
    startLater: function () {
        this.gamePlayerNode.onStart();
        this.joinLate = false;
        if(confige.curReconnectData == -1)  //是否属于重连状态
        {
            for(var i in confige.roomPlayer)
                if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                    this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
            if(this.joinState != 1001)   //本局游戏已经开始才加入
            {
                this.gameBegin = true;
                this.gameInfoNode.btn_inviteFriend.active = false;
                console.log("本局游戏已经开始才加入,进入观战模式");
                console.log("当前参与游戏的人数===" + this.gamePlayerNode.playerCount);
                var watchPlayer = 0;
                for(var i in confige.roomPlayer)
                {
                    if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == false)
                    {
                        watchPlayer ++;
                        console.log("有一个观战的玩家");
                        if(i == this.meChair){
                            this.joinLate = true;
                        }
                    }
                    if(confige.roomPlayer[i].isBanker == true)
                    {
                        this.curBankerChair = i;
                        this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setBanker();
                    }
                }
                this.gamePlayerNode.playerCount -= watchPlayer;
                this.readyBtn.active = false;
                this.gameStart = true;

                if(this.joinState == 1003)
                {
                    for(var i in confige.roomPlayer)
                    {
                        if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                        {   
                            this.gamePlayerNode.playerCardList[i] = confige.roomData.player[i].handCard;
                            this.gamePlayerNode.playerListNew[confige.getCurChair(i)].initCardWithBack();
                            var curChair = confige.getCurChair(i);
                            if(curChair != 0 && confige.roomPlayer[i].isShowCard == true)
                                this.gamePlayerNode.showOneCard(i);
                            this.gamePlayerNode.playerListNew[curChair].showCardBackWithCount(2);
                        }
                    }
                }

                if(this.joinState != 1005)      //非抢庄阶段，显示分数和庄家
                {
                    var curBetCount = 0;
                    for(var i in confige.roomPlayer)
                    {
                        if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                        {  
                            var curChair = confige.getCurChair(i);
                            if(confige.roomData.betList[i] == null)
                                confige.roomData.betList[i] = 0;
                            curBetCount += confige.roomData.betList[i];
                            this.gamePlayerNode.curBetNumList[curChair] = confige.roomData.betList[i];
                            
                            if(confige.roomPlayer[i].isBanker == false)
                            {
                                this.gamePlayerNode.playerListNew[curChair].setBet(this.gamePlayerNode.curBetNumList[curChair]);
                                this.updatePlayerScore(curChair,this.gamePlayerNode.curBetNumList[curChair])
                            }
                                
                        }
                    }
                    this.allBetNum = curBetCount;
                    this.showScorePool(this.allBetNum);
                    var curChairBet = window.DKTools.cutBetNum(this.allBetNum);
                    for(var j in curChairBet)
                        this.gameBGNode.betItemListAddBetNew(confige.getCurChair(this.curBankerChair),curChairBet[j]);
                    
                    if(confige.roomData.bankerMode == 8)
                    {
                        this.curRobMaxNum = confige.roomData.maxRob;
                        if(this.curRobMaxNum == 0)
                        {
                            this.robMaxNumLabel.string = "本局"+1+"倍";
                        }else{
                            this.robMaxNumLabel.string = "本局"+this.curRobMaxNum+"倍";
                        }
                        this.robMaxNumNode.active = true;
                    }
                }                      
            }
        }else{
            this.recoverGame();
            confige.curReconnectData = -1;
        }
        console.log("roomId + meChair === " + (confige.roomData.roomId*10 + this.meChair));
        

        this.sceneLoadOver = true;
        
        //处理缓存的服务器消息
        confige.gameSceneLoadOver = true;
        confige.curSceneIndex = 2;
        var infoCount = confige.gameSceneLoadData.length;
        console.log(confige.gameSceneLoadData);
        for(var i=0;i<infoCount;i++)
        {
            console.log("deal once!!!!!!!!");
            var curInfo = confige.gameSceneLoadData.shift();
            pomelo.dealWithOnMessage(curInfo);
            console.log(curInfo);
        }
        confige.gameSceneLoadData = [];
        console.log(confige.gameSceneLoadData);
    },

    setBanker:function(chair){
        this.curBankerChair = chair;
    },

    showScorePool:function(score,type,bankerScore,change){
        console.log("show fuck score pool!!!!!!");
        this.gameBGNode.scorePool.active = true;
        this.gameBGNode.scorePoolLabel.string = "总下注："+score+"分";
        this.gameBGNode.scorePoolNum = parseInt(score);

        if(bankerScore)
        {
            console.log("curChair === " + this.curBankerChair + "newChiar===" + confige.getCurChair(this.curBankerChair));
            this.gamePlayerNode.playerScoreList[this.curBankerChair] = bankerScore;
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setScore(this.gamePlayerNode.playerScoreList[this.curBankerChair]);
        }
        if(change === true)
        {
            // this.gameBGNode.betItemRemoveToBanker(confige.getCurChair(this.curBankerChair));
            var callFunc = function(){
                this.gameBGNode.betItemListClean();
                console.log("fuck you scorePool 丢钱出去！！！！！！！！！！！！！！")
                var curChairBet = window.DKTools.cutBetNum(callFunc.score);
                for(var j in curChairBet)
                    this.gameBGNode.betItemListAddBetNew(confige.getCurChair(this.curBankerChair),curChairBet[j]);
            };
            callFunc.score = score;
            this.scheduleOnce(callFunc,1);
        }
    },

    showGameStatus:function(index){
        this.gameStatus.active = true;
        for(var i=1;i<=5;i++)
            this.gameStatusList[i].active = false;
        this.gameStatusList[index].active = true;
    },

    hideGameStatus:function(){
        this.gameStatus.active = false;
    },

    addBet:function(betNum, chair){
        this.gameBGNode.betItemListAddBetNew(chair,betNum);
        this.updatePlayerScore(chair,betNum)
        this.allBetNum = this.allBetNum + betNum;
        if(chair == 0)
            this.myBetNum = this.myBetNum + betNum;
        if(this.gameMode != 3)
            this.showScorePool(this.allBetNum,1);
        this.gamePlayerNode.curBetNumList[chair] += betNum;
        this.gamePlayerNode.playerListNew[chair].setBet(this.gamePlayerNode.curBetNumList[chair]);
        if(confige.soundEnable == true)
            confige.playSoundByName("sendBet");
    },

    onBtnReadyClicked:function(){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        if(confige.roomData.bankerMode == 8)
            this.hideBankerAni();
        if(this.btnCanSend)
        {
            this.btnCanSend = false;
            pomelo.request("connector.entryHandler.sendData", {"code" : "ready"}, function(data) {
                console.log("flag is : "+ data.flag);
                if(data.flag == true)
                {
                    console.log("fuck onBtnReadyClicked !!!!!!!!!");
                    this.readyBtn.active = false;
                }
                this.btnCanSend = true;
            }.bind(this));
        }
    },
    
    onBtnBetClicked:function(event, customEventData){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var betType = parseInt(customEventData);
        var curBetNum = this.betNumList[betType];
        var self = this;
        pomelo.clientSend("bet",{"bet": curBetNum},function(){
            if(confige.roomData.bankerMode != 7)
                self.closeBetBtn();
            console.log("bet call back");
        });

    },
    
    onBtnPushBankerClicked:function(event,customEventData){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var clickIndex = parseInt(customEventData);
        this.pushBanker.active = false;
        this.unpushBanker.active = false;
        if(clickIndex == 1)
        {
            this.showGameStatus(3);
            pomelo.clientSend("robBanker",{"flag" : true});
        }else if(clickIndex == 2){
            this.showGameStatus(3);
            pomelo.clientSend("robBanker",{"flag" : false});
        }
    },
    
    onBtnPopBankerClicked:function(){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        pomelo.clientSend("downBanker");
    },

    downBanker:function(data){
        if(this.gameMode == 3)
            this.gameBGNode.betItemRemoveToBanker(confige.getCurChair(data.chair));
        else
            this.showScorePool(data.bonusPool,0);
            // this.showScorePool(data.bonusPool,0,false,true);
        this.gamePlayerNode.playerListNew[confige.getCurChair(data.chair)].hideBanker();
        this.gamePlayerNode.playerListNew[confige.getCurChair(data.banker)].setBanker();
        // if(this.gameMode == 3)
        // {
        //     this.gameBGNode.betItemRemoveToBanker(confige.getCurChair(data.chair));
        // } 
        if(data.oldBankerScore)
        {
            this.gamePlayerNode.playerScoreList[data.chair] = data.oldBankerScore;
            this.gamePlayerNode.playerListNew[confige.getCurChair(data.chair)].setScore(this.gamePlayerNode.playerScoreList[data.chair]);
        }
        if(data.bankerScore)
        {
            this.curBankerChair = data.banker;
            this.gamePlayerNode.playerScoreList[this.curBankerChair] = data.bankerScore;
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setScore(this.gamePlayerNode.playerScoreList[this.curBankerChair]);
        }
        /*alert('什么鬼');/*   */
    },
    
    onServerRobBanker:function(){
        this.timerItem.setTime(this.time_rob);
        this.showGameStatus(1);
        if(this.joinLate == false)
        {
            if(confige.roomData.bankerMode == 8)
                this.robBtnBox.active = true;
            else{
                this.unpushBanker.active = true;
                this.pushBanker.active = true;
            }
        }
        console.log("fuck rob banker");
    },
    
    onServerRobBankerReturn:function(data){
        var curChair = confige.getCurChair(data.chair);
        if(confige.roomData.bankerMode == 8)
        {
            if(data.num > this.curRobMaxNum)
                this.curRobMaxNum = data.num;
            if(data.num == 0)
                this.gamePlayerNode.playerListNew[curChair].setNoRob();
            else{
                this.gamePlayerNode.playerListNew[curChair].setRobMore(data.num);
                this.bankerRunList.push(curChair);
            }
            return;
        }
        if(data.flag == 1)
        {
            this.gamePlayerNode.playerListNew[curChair].setRob();
        }else if(data.flag == 2){
            this.gamePlayerNode.playerListNew[curChair].setNoRob();
        }
    },

    statusChange:function(index){
        if(index === 1)
        {
            this.timerItem.setTime(this.time_betting);
        }
        else if(index === 2)
        {
            this.timerItem.setTime(this.time_settlement);
        }
    },
    
    onServerReady:function(chair){
        confige.roomPlayer[confige.getOriChair(chair)].isReady = true;
        console.log(confige.getOriChair(chair) + "号玩家准备");
        this.onReConnect = false;
        this.gamePlayerNode.playerListNew[chair].setReady();
        if(chair == 0)      //当前玩家自己
        {
            this.curRobMaxNum = 0;
            if(confige.roomData.bankerMode == 8)
                this.robMaxNumNode.active = false;
            this.deactiveShowCardBtn();
            this.joinLate = false;
            if(this.gameMode != 3)
                this.gameBGNode.betItemListClean();
            this.showGameStatus(5);
            if(confige.roomData.gameMode != 3)
                this.gameBGNode.scorePool.active = false;
            for(var i in confige.roomPlayer)
            {
                if(confige.roomPlayer[i].isActive == true)
                {   
                    var curChair = confige.getCurChair(i);
                    this.gamePlayerNode.playerListNew[curChair].resetCard();
                    // this.gamePlayerNode.playerList[curChair].getChildByName("banker").active = false;
                    // this.gamePlayerNode.betNumNodeList[curChair].active = false;
                    // this.gamePlayerNode.betNumLabelList[curChair].string = "0" + "分";
                    // this.gamePlayerNode.curBetNumList[curChair] = 0;
                }
            }
        }
    },

    btnClickRobBox:function(event,customEventData){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        console.log("btnClickRobBox@@@@@@@@@@@@@@@");
        var index = parseInt(customEventData);
        switch(index){
            case 1:
                pomelo.clientSend("robBanker",{"num" : 1});
                break;
            case 2:
                pomelo.clientSend("robBanker",{"num" : 2});
                break;
            case 3:
                pomelo.clientSend("robBanker",{"num" : 3});
                break;
            case 4:
                pomelo.clientSend("robBanker",{"num" : 4});
                break;
            case 0:
                pomelo.clientSend("robBanker",{"num" : 0});
                break;
        }
        this.robBtnBox.active = false;
    },
    
    onServerBeginBetting:function(data){
        this.curBankerChair = data.banker;
        if(confige.roomData.bankerMode == 8){
            this.robBtnBox.active = false;
            this.runBankerAni(confige.getCurChair(this.curBankerChair));
        }else{
            this.showBankerAfterAni();
        }
    },
    showBankerAfterAni:function(){
        window.DKTools.audioEG.playEffect("tips_betPlease");
        this.allBetNum = 0;
        this.myBetNum = 0;

        this.statusChange(1);
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
            {
                var curIndex = confige.getCurChair(i);
                if(i != this.curBankerChair)
                {
                    this.gamePlayerNode.playerListNew[curIndex].setBet(0);
                    this.gamePlayerNode.curBetNumList[curIndex] = 0;
                }
            }
        }
        console.log("onServerBeginBetting111111");
        if(this.curBankerChair == this.meChair){
            this.showGameStatus(4);
        }
        else{
            
            this.openBetBtn();
            this.showGameStatus(2);
        }
      
        if(confige.roomData.gameMode != 3)
            this.showScorePool(this.allBetNum);

        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true)
            {   
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideBanker();
            }
        }
        console.log("onServerBeginBetting222222");
        if(this.curBankerChair != -1)
        {
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setBanker();
        }
        console.log("onServerBeginBetting333333");
        if(this.joinLate == false)
        {
            this.pushBanker.active = false;
            this.unpushBanker.active = false;
        }else{
            if(this.joinState == 1005 &&  this.cardMode == 2)
            {
                for(var i in confige.roomPlayer)
                {
                    if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                    {
                        var curChair = confige.getCurChair(i);
                        if(curChair != 0)
                            this.playerListNew[curChair].showCardBackWithCount(2);
                    }
                }
            }
        }

        if(confige.roomData.bankerMode == 8)
        {   
            if(this.curRobMaxNum == 0)
            {
                this.robMaxNumLabel.string = "本局"+1+"倍";
            }else{
                this.robMaxNumLabel.string = "本局"+this.curRobMaxNum+"倍";
            }
            this.robMaxNumNode.active = true;
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].resetStatus();
        }
        console.log("onServerBeginBetting444444");
    },

    onServerDealCard:function(data){
        var handCards = data.handCards;
        this.closeBetBtn();
        this.hideGameStatus();

        for(var i in handCards)
        {
            if(handCards.hasOwnProperty(i))
            {
                this.gamePlayerNode.playerCardList[i] = handCards[i];
                console.log("confige.getCurChair(i)======"+confige.getCurChair(i));
            }
        }
        this.statusChange(2);

        if(this.cardMode == 2 && this.joinLate == false)
        {
            console.log("onServerDealCard11111222");
        }else{
            console.log("onServerDealCard333333");
            this.newDisCard(2);
        }


    },
    //发牌完再现实开牌按钮
    alldisCardover:function(){
        if(this.joinLate == false)
        {
            var callFunc2 = function(){
                this.activeShowCardBtn();
            };
            this.scheduleOnce(callFunc2,0.5);
        }

    },
    activeShowCardBtn:function(){
        this.showCardBtn.active = true;
        this.moveCardBtn.active = true;
    },

    deactiveShowCardBtn:function(){
        this.showCardBtn.active = false;
        this.moveCardBtn.active = false;
    },

    btn_showMyCard:function(event,customEventData){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var index = parseInt(customEventData);
        if(index)
        {
            this.deactiveShowCardBtn();
            this.onMoveCard = true;
            var handCard = this.gamePlayerNode.playerCardList[this.meChair];
            this.moveCardLayer.showLayerB(handCard);
        }else{
            pomelo.clientSend("showCard");
            this.deactiveShowCardBtn();
            var handCard = this.gamePlayerNode.playerCardList[this.meChair];
            var curNiuType = 0;
            curNiuType = PaiGowLogic.getType(handCard);
            var isShowB = false;
            if(curNiuType.type >= 1 && curNiuType.type <=9 && curNiuType.card.num == 10)
                isShowB = true;
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.meChair)].showCardType(curNiuType.type,isShowB);
        }
    },
    
    btnShowCardOnMove:function(){
        this.onMoveCard = false;
        pomelo.clientSend("showCard");
        this.deactiveShowCardBtn();
        this.moveCardLayer.hideLayerB();

        var handCard = this.gamePlayerNode.playerCardList[this.meChair];
        var curNiuType = 0;
        curNiuType = PaiGowLogic.getType(handCard);
        var isShowB = false;
        if(curNiuType.type >= 1 && curNiuType.type <=9 && curNiuType.card.num == 10)
            isShowB = true;
        this.gamePlayerNode.playerListNew[confige.getCurChair(this.meChair)].showCardType(curNiuType.type,isShowB);
    },

    showMingCard:function(cards){
        var cardsCount = 0;
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
            {
                var curChair = confige.getCurChair(i);
            }
        }
        for(var i in cards)
        {
            cardsCount ++;
        }
        
        this.newDisCard(cardsCount);

        var callFunc = function(){
            for(var i in callFunc.cards)
            {
                this.gamePlayerNode.playerListNew[0].setCardWithIndex(i, callFunc.cards[i].num, callFunc.cards[i].type);
            }
        };
        callFunc.cards = cards;
        this.scheduleOnce(callFunc,0.5);
    },

    onServerSettlement:function(data){
        if(this.onMoveCard)
        {
            this.onMoveCard = false;
            this.moveCardLayer.btnShowCardClickB();
        }
        this.hideOpenCard(1);
        this.hideOpenCard(2);
        this.deactiveShowCardBtn();
        this.hideGameStatus();
        // if(this.gameMode != 3)      //
        //     this.betItemListClean();
        console.log("onServerSettlement 1111111");
        this.statusChange(0);

        console.log("onServerSettlement 222222222");
        //第一步显示玩家手牌
        for(var i in data.result)
        {
            if(data.result.hasOwnProperty(i) && data.player[i].isReady)
            {
                this.gamePlayerNode.showOneCard(i);
                if(parseInt(data.player[i].uid) == parseInt(confige.userInfo.playerId))
                {
                    if(data.curScores[i] >= 0)
                        this.winLoseNode.showLayer(true);
                    else
                        this.winLoseNode.showLayer(false);
                }
            }
        }
        console.log("onServerSettlement 33333333");
        this.waitForSettle = true;
        this.deactiveShowCardBtn();
        this.gameStart = false;
        this.joinLate = false;
        this.gameInfoNode.btn_close.interactable = true;
        this.timerItem.hideTimer();

        for(var i in confige.roomPlayer)
        {            
            if(confige.roomPlayer[i].isActive == true)            
            {
                confige.roomPlayer[i].isReady = false;
            }
        }

        //分割筹码
        console.log("分割筹码");
        console.log(data.curScores);
        if(confige.roomData.bankerMode == 7)//开船模式特殊处理
        {
            var maxNum = 0;
            for(var i in data.curScores)
            {
                if(data.curScores[i] > maxNum){
                    maxNum = data.curScores[i];
                    this.curBankerChair = i;
                }
            }
        }
            console.log("this.curBankerChair111==="+this.curBankerChair);
            console.log("this.curBankerChair222==="+confige.getCurChair(this.curBankerChair));
            this.gameBGNode.betItemRemoveToBanker(confige.getCurChair(this.curBankerChair));
            if(confige.soundEnable == true)
                confige.playSoundByName("getBet");
            var sendBetFunc = function(){
                this.gameBGNode.betItemSendFromBanker(data.curScores,confige.getCurChair(this.curBankerChair));
                if(confige.soundEnable == true)
                    confige.playSoundByName("getBet");
            };

            this.scheduleOnce(sendBetFunc,2.25);

        console.log("onServerSettlement 4444444");
        for(var i in data.curScores)
        {
            var str =  ""
            if(data.curScores[i] > 0)
            {
                str = "+" + Math.round(parseInt(data.curScores[i])) + "分" 
            }
            else
            {
                str = Math.round(parseInt(data.curScores[i])) + "分" 
            }
            this.addScoreList[confige.getCurChair(i)].active = true
            this.addScoreList[confige.getCurChair(i)].getComponent(cc.Label).string = str
        }
        var hideAddScoreList = function(){
            for(var i=0;i<=8;i++)
            {
                this.addScoreList[i].active = false
            }
        }
        this.scheduleOnce(hideAddScoreList,2.25);
        //第二步延迟显示结算界面
        var self = this;
        var playerData = new Array()
        var playerNum = 0;
        for(var i in data.result)
        {
            if(data.result.hasOwnProperty(i) && data.player[i].isReady)
            {
                var playerinfo = {}
                playerinfo.type = data.result[i].type
                playerinfo.index = i
                playerinfo.score = data.curScores[i]
                playerData.push(playerinfo)
                playerNum++;
            }
        }
        console.log(playerData.length)
        for(var i=0;i< playerData.length;i++)
        {
            for(var j=0;j < playerData.length - 1 - i;j++)
            {
                
                if(playerData[j].type <= playerData[j+1].type)
                {
                    if(!(playerData[j].type == playerData[j+1].type && playerData[j].score >playerData[j+1].score ))
                    {
                        var them = playerData[j]
                        playerData[j] = playerData[j+1]
                        playerData[j+1] = them
                    }
                   
                }
            }
        }
        var showSettleFunc1 = function(){
            self.gameInfoNode.settleLayer.show(data.curScores[self.meChair]);
            //结算界面屏蔽离线用户
            var indexNum = 0
            console.log("结算。。。。。。。。。。。。。。。。。。。")
            console.log(data.result)
            for(var i in playerData)
            {
                var index = parseInt(playerData[i].index)
                if(data.result.hasOwnProperty(index) && data.player[index].isReady)
                {
                    var niuType = data.result[index].type;
                    
                    self.gameInfoNode.settleLayer.addOneSettle(confige.roomData.player[index].playerInfo.nickname, niuType, data.curScores[index],2,data.player[index].handCard,indexNum,null,data.result[index].card.num);
                    self.gamePlayerNode.playerScoreList[index] = data.realScores[index];
                    self.gamePlayerNode.playerListNew[confige.getCurChair(index)].setScore(self.gamePlayerNode.playerScoreList[index]);
                    indexNum++;
                    if(index == self.meChair)
                        self.updateMeScore(data.realScores[index]);
                }
            }
            if(confige.roomData.bankerMode == 7)
                self.gameInfoNode.settleLayer.updateSettleNew(data);
            console.log("onServerSettlement 55555555");
            self.waitForSettle = false;
        };
        
        var showSettleFunc2 = function(){
            if(this.gameInfoNode.settleLayer == -1){
                var curPrefabStr = "settleLayer";
                if(confige.roomData.bankerMode == 7)
                    curPrefabStr = "settleLayerNew";
                cc.loader.loadRes("prefabs/game/"+curPrefabStr, cc.Prefab, function (err, prefabs) {
                    var newLayer = cc.instantiate(prefabs);
                    self.gameInfoNode.layerNode1.addChild(newLayer,10);
                    self.gameInfoNode.settleLayer = newLayer.getComponent("settleLayer");
                    self.gameInfoNode.settleLayer.showLayer();
                    self.gameInfoNode.settleLayer.parent = self;
                    if(confige.roomData.bankerMode == 7)
                        self.gameInfoNode.settleLayer.isNewType = true;
                    showSettleFunc1();
                });
            }else{
                self.gameInfoNode.settleLayer.showLayer();
                showSettleFunc1();
            }
        };
        this.scheduleOnce(showSettleFunc2,5);
    },

    resetScene:function(){
        this.pushBanker.active = false;
        this.unpushBanker.active = false;
        this.readyBtn.active = true;
        this.deactiveShowCardBtn();
        this.timerItem.active = false;
    },
    //更新玩家分数
    updatePlayerScore:function(chairid,addSorce){
        var self = this
        if(chairid == 0)
        {
            self.updateMeScore(parseInt(this.mainPlayerScore.string)-parseInt(addSorce));
        }
        else
        {
            var score = self.gamePlayerNode.playerListNew[chairid].curScore
            self.gamePlayerNode.playerListNew[chairid].setScore(parseInt(score) - parseInt(addSorce));
        }
    },
    //根据重连数据重现游戏状态
    recoverGame:function(){
        this.onReConnect = true;
        if(confige.curReconnectData.state == 1100){
            gameData.gameInfoNode.btn_continue.active = true;
            this.readyBtn.active = false;
            this.gameInfoNode.btn_inviteFriend.active = false;
            return;
        }
        console.log("处理重连数据");
        console.log("当前参与游戏的人数===" + this.gamePlayerNode.playerCount);
        var watchPlayer = 0;
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == false)
            {   
                watchPlayer ++;
                if(i == this.meChair){
                    this.joinLate = true;
                    this.updateMeScore(confige.roomPlayer[i].score);
                }
            }
        }
        this.gamePlayerNode.playerCount -= watchPlayer;

        if(confige.curReconnectData.freeState && confige.curReconnectData.freeState != false)
            this.gameInfoNode.onServerShowFinish(confige.curReconnectData.freeState);
        console.log("on recoverGame() !!!!!!!!!!!!!");
        this.gameInfoNode.roomMaxTime = confige.curReconnectData.roomInfo.maxGameNumber;
        //重置场景
        this.resetScene();
        console.log(confige.roomPlayer);
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true)
            {
                if(confige.roomPlayer[i].isReady == true)
                    this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));

                if(confige.roomPlayer[i].isOnline == false)
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setLeave();
                else
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideLeave();
            }
        }
        //重现当前玩家分数和显示庄家
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true)
            {
                if(this.gamePlayerNode.playerActiveList[confige.getCurChair(i)] == false)
                {
                    console.log("this.playerActiveList === addone");
                    this.gamePlayerNode.addOnePlayer(confige.roomPlayer[i]);
                }
                if(confige.curReconnectData.betList[i] == null)
                    confige.curReconnectData.betList[i] = 0;
                this.gamePlayerNode.playerScoreList[i] = confige.curReconnectData.roomInfo.player[i].score;
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setScore(this.gamePlayerNode.playerScoreList[i]);
                if(confige.curReconnectData.roomInfo.player[i].isBanker == true)
                {
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setBanker();
                    this.curBankerChair = i;
                    console.log("重连时庄家==="+this.curBankerChair);
                }
            }
        }
        //重现下注金额
        this.gameInfoNode.roomCurTime = confige.curReconnectData.roomInfo.gameNumber;
        this.gameInfoNode.roomTime.string = "第" + this.gameInfoNode.roomCurTime + "/" + this.gameInfoNode.roomMaxTime + "局";
        if(confige.curReconnectData.state != 1001)
        {
            if(confige.curReconnectData.state != 1005)
            {
                var curBetCount = 0;
                for(var i in confige.roomPlayer)
                {
                    if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                    {
                        var curChair = confige.getCurChair(i);
                        if(curChair == 0)
                        {
                            this.myBetNum = confige.curReconnectData.betList[i];
                        }
                        curBetCount += confige.curReconnectData.betList[i];
                        this.gamePlayerNode.curBetNumList[curChair] = confige.curReconnectData.betList[i];
                        this.gamePlayerNode.playerListNew[curChair].setBet(this.gamePlayerNode.curBetNumList[curChair]);
                        this.updatePlayerScore(curChair,this.gamePlayerNode.curBetNumList[curChair])
                    }
                }
                this.allBetNum = curBetCount;
                this.showScorePool(this.allBetNum);
                var curChairBet = window.DKTools.cutBetNum(this.allBetNum);
                for(var j in curChairBet)
                    this.gameBGNode.betItemListAddBetNew(confige.getCurChair(this.curBankerChair),curChairBet[j]);

                console.log("重连maxRob======="+ confige.curReconnectData.roomInfo.maxRob);
                console.log(confige.curReconnectData.roomInfo);
                this.curRobMaxNum = confige.curReconnectData.roomInfo.maxRob;
                if(confige.roomData.bankerMode == 8)
                {
                    if(this.curRobMaxNum == 0)
                    {
                        this.robMaxNumLabel.string = "本局"+1+"倍";
                    }else{
                        this.robMaxNumLabel.string = "本局"+this.curRobMaxNum+"倍";
                    }
                    this.robMaxNumNode.active = true;
                }
            }
            this.readyBtn.active = false;

            //重现当前局数显示
            // this.gameInfoNode.roomCurTime = confige.curReconnectData.roomInfo.gameNumber;
            // this.gameInfoNode.roomTime.string = "第" + this.gameInfoNode.roomCurTime + "/" + this.gameInfoNode.roomMaxTime + "局";
            console.log("重连"+ this.gameInfoNode.roomTime.string);
            this.gameBegin = true;
            // this.gameInfoNode.btn_close.interactable = false;
            this.gameInfoNode.btn_inviteFriend.active = false;
        }else{
            //重现当前局数显示
            // this.gameInfoNode.roomCurTime = confige.curReconnectData.roomInfo.gameNumber + 1;
            // this.gameInfoNode.roomTime.string = "第" + this.gameInfoNode.roomCurTime + "/" + this.gameInfoNode.roomMaxTime + "局";
            console.log("重连"+ this.gameInfoNode.roomTime.string);
            for(var i in confige.roomPlayer)
            {
                if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                {
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setReady();
                    if(i == this.meChair)
                        this.readyBtn.active = false;
                }
            }
        }

        switch(confige.curReconnectData.state){
            case 1001:      //空闲阶段
                if(this.curBankerChair != -1)
                    this.gamePlayerNode.playerListNew[this.curBankerChair].hideBanker();
                break;
            case 1002:      //下注阶段
                if(this.curBankerChair != this.meChair && this.joinLate == false)
                    this.openBetBtn();
                break;
            case 1003:      //发牌阶段
                for(var i in confige.roomPlayer)
                {
                    if(confige.roomPlayer[i].isActive == true && confige.roomPlayer[i].isReady == true)
                    {
                        this.gamePlayerNode.playerCardList[i] = confige.curReconnectData.roomInfo.player[i].handCard;
                        this.gamePlayerNode.playerListNew[confige.getCurChair(i)].initCardWithBack();
                        if(confige.roomPlayer[i].isShowCard == true)
                            this.gamePlayerNode.showOneCard(i);
                    }
                }
                if(confige.roomPlayer[this.meChair].isShowCard)
                    this.deactiveShowCardBtn();
                else
                    this.activeShowCardBtn();
                break;
            case 1005:      //抢庄阶段
                // this.statusChange(1);
                //this.pushBanker.active = true;
                if(this.gameMode == 1 && this.joinLate == false)
                    this.onServerRobBanker();
                break;
        }

        if(this.gameInfoNode.roomCurTime != 0)
        {
            this.gameInfoNode.btn_inviteFriend.active = false;
            this.gameBegin = true;
        }else{
            console.log("fuck roomCurTime === " + this.roomCurTime);
        }
        confige.curReconnectData = -1;
    },

    connectCallBack:function(){

    },

    onNewGameStart:function(){
        if(this.gameInfoNode.settleLayerLoad != -1 && this.gameInfoNode.settleLayer.onShow == true){
            this.gameInfoNode.settleLayer.hideNoClick();
            if(this.isZhajinniu)
            {
                for(var i=0;i<confige.playerMax;i++)
                {
                    this.lookCardList[i] = false;
                    this.giveUpList[i] = false;
                    this.loseList[i] = false;
                    this.loseNodeList[i].active = false;
                }
            }
            this.deactiveShowCardBtn();
            
            this.gameBGNode.betItemListClean();
            this.gameBGNode.scorePool.active = false;

            for(var i in confige.roomPlayer)
            {
                if(confige.roomPlayer[i].isActive == true)
                {   
                    var curChair = confige.getCurChair(i);
                    this.gamePlayerNode.playerListNew[curChair].resetCard();
                    this.gamePlayerNode.playerListNew[curChair].hideBanker();
                    this.gamePlayerNode.playerListNew[curChair].setBet(0);
                    this.gamePlayerNode.curBetNumList[curChair] = 0;
                }
            }
        }
        // if(confige.roomPlayer[this.meChair].isReady == false)
            // this.joinLate = true;
        this.readyBtn.active = false;
        this.joinLate = false;

        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true)
            {
                if(confige.roomPlayer[i].isReady == true)
                {
                    confige.roomPlayer[i].isReady = true;
                    console.log("激活"+i+"号玩家发牌器");
                    this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
                }
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideBanker();
            }
        }
        this.gameBegin = true;
        this.gameStart = true;
        this.meGiveUp = false;
        this.newResetCard();
        console.log("onNewGameStart");
        this.gameInfoNode.roomCurTime ++;
        this.gameInfoNode.roomTime.string = "第" + this.gameInfoNode.roomCurTime + "/" + this.gameInfoNode.roomMaxTime + "局";
        for(var i=0;i<confige.playerMax;i++)
        {
            this.gamePlayerNode.playerListNew[i].hideReady();
        }
        this.gameInfoNode.btn_inviteFriend.active = false;
        // this.gameInfoNode.btn_close.interactable = false;
        this.gamePlayerNode.playerCount = this.gamePlayerNode.newPlayerCount;
        this.gamePlayerNode.noShowCardCount = this.gamePlayerNode.playerCount;
        if(confige.roomData.gameMode != 3)
            this.showScorePool(0);
    },

    onNewGameBegin:function(data){
        this.gameStart = true;
        this.gamePlayerNode.playerCount = this.gamePlayerNode.newPlayerCount;
        console.log("onNewGameBegin" + this.gamePlayerNode.playerCount);
        this.allBetNum = 0;
        
        this.showScorePool(this.allBetNum);
    },

    update: function (dt) {
        window.GVoice.gvoicePoll();
    },

    newDisCard:function(times){
        this.gamePlayerNode.cardItemList.disPaiGow();
        // if(times == 1)
        //     this.gamePlayerNode.cardItemList.disCardOneRound();
        // else
        //     this.gamePlayerNode.cardItemList.disCardWithRoundTime(times);
    },

    newResetCard:function(){
        this.gamePlayerNode.cardItemList.resetCardList();
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true)
            {
                if(confige.roomPlayer[i].isReady == true)
                    this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
            }
        }
    },

    showOpenCard:function(index){
        return;
        this.openCardBox.active = true;
        var moveAction = cc.repeatForever(cc.sequence(cc.moveBy(0.5,cc.p(0,20)),cc.moveBy(0.5,cc.p(0,-20))));
        if(index == 1)
        {
            this.openCardBtn1.active = true;
            this.openCardImg1.active = true;
            this.openCardImg1.y = -280;
            this.openCardImg1.runAction(moveAction);
        }else if(index == 2){
            this.openCardBtn2.active = true;
            this.openCardImg2.active = true;
            this.openCardImg2.y = -280;
            this.openCardImg2.runAction(moveAction);
        }
    },

    hideOpenCard:function(index){
        return;
        this.openCardBox.active = true;
        if(index == 1)
        {
            this.openCardBtn1.active = false;
            this.openCardImg1.active = false;            
            this.openCardImg1.stopAllActions();
        }else if(index == 2){
            this.openCardBtn2.active = false;
            this.openCardImg2.active = false;            
            this.openCardImg2.stopAllActions();
        }
    },

    btnOpenCard:function(event,customEventData){
        var index = parseInt(customEventData);
        if(index == 1)
        {
            this.hideOpenCard(1);
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.meChair)].setCardWithIndex(1, this.gamePlayerNode.playerCardList[this.meChair][1].num, this.gamePlayerNode.playerCardList[this.meChair][1].type);
        }else if(index == 2){
            this.hideOpenCard(2);
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.meChair)].setCardWithIndex(2, this.gamePlayerNode.playerCardList[this.meChair][2].num, this.gamePlayerNode.playerCardList[this.meChair][2].type);
        }
    },

    openShare:function(){
        if(confige.curOverLayer != -1)
            confige.curOverLayer.openShare();
    },

    WXCancle:function(){
        if(confige.curOverLayer != -1)
            confige.curOverLayer.openShare();
    },

    showReConnect:function(){
        gameData.gameInfoNode.showReConnect();
        console.log("showReConnect!!!!!!!!!");
    },

    hideReConnect:function(){
        gameData.gameInfoNode.hideReConnect();
        console.log("hideReConnect!!!!!!!!!");
    },

    sayWithID:function(voiceID){
        pomelo.clientSend("say",{"msg": {"sayType":255, "id": voiceID, "time": this.gameInfoNode.sayTime}});
    },

    readyBegin:function(time){
        this.timerItem.setTime(parseInt(time/1000)); 
    },

    loadRes1:function(){
        var self = this;
        var onLoadNext = false;
        var loadCard = false;
        var loadNiutype = false;
        //cardFrame
        cc.loader.loadRes("prefabs/game/cardNode", cc.Prefab, function (err, prefabs) {
            var newNode = cc.instantiate(prefabs);
            self.resNode.addChild(newNode);
            confige.paiGowCardFrameMap[0] = newNode.getChildByName("card10").getComponent("cc.Sprite").spriteFrame;
            for(var i=0;i<=10;i++)
            {
                confige.paiGowCardFrameMap[i] = newNode.getChildByName("card"+i).getComponent("cc.Sprite").spriteFrame;
            }
            loadCard = true;
            if(loadCard == true && loadNiutype == true)
            {
                if(onLoadNext == false)
                {
                    onLoadNext = true;
                    self.loadLater();
                    self.startLater();
                    self.loadRes2();
                    self.initAudio();
                }
            }
        });
        
        
        //niutypeFrame
        cc.loader.loadRes("prefabs/game/typeNode", cc.Prefab, function (err, prefabs) {
            var newNode = cc.instantiate(prefabs);
            self.resNode.addChild(newNode);
            for(var i=0;i<=10;i++)
            {
                var spriteFrame = newNode.getChildByName("type"+i).getComponent("cc.Sprite").spriteFrame;
                confige.paiGowTypeFrameMap[i] = spriteFrame;
            }
            for(var i=1;i<=9;i++)
                confige.paiGowTypeFrameMapB[i] = newNode.getChildByName("type"+i+"B").getComponent("cc.Sprite").spriteFrame;
            loadNiutype = true;
            if(loadCard == true && loadNiutype == true)
            {
                if(onLoadNext == false)
                {
                    onLoadNext = true;
                    self.loadLater();
                    self.startLater();
                    self.loadRes2();
                    self.initAudio();
                }
            }
        });
    },

    loadRes2:function(){
        var self = this;
        //faceAni
        cc.loader.loadRes("prefabs/game/faceAniNode", cc.Prefab, function (err, prefabs) {
            var newNode = cc.instantiate(prefabs);
            self.resNode.addChild(newNode);
            for(var i=1;i<=6;i++)
                confige.faceAniMap[i] = newNode.getChildByName("faceAni"+i);
            confige.loadFaceAni = true;
        });
    },

    initAudio:function(){
        for(var i=0;i<=20;i++)
        {
            cc.loader.loadRes("sound/cardType/0/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "female_" + "type_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/1/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "male_" + "type_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/2/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "banker_" + "type_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }
        for(var i=1;i<=9;i++)
        {
            cc.loader.loadRes("sound/cardType/0/"+i+"B",function(index){
                return  function (err, audio) {
                    var curIndex = "female_" + "type_" + index + "B";
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/1/"+i+"B",function(index){
                return  function (err, audio) {
                    var curIndex = "male_" + "type_" + index + "B";
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/2/"+i+"B",function(index){
                return  function (err, audio) {
                    var curIndex = "banker_" + "type_" + index + "B";
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }

        for(var i=1;i<=6;i++)
        {
            cc.loader.loadRes("sound/face/F_" + (i),function(index){
                return  function (err, audio) {
                    var curIndex = "female_" + "face_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/face/M_" + (i),function(index){
                return  function (err, audio) {
                    var curIndex = "male_" + "face_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }
        for(var i=1;i<=7;i++)
        {
            cc.loader.loadRes("sound/face/" + (i),function(index){
                return  function (err, audio) {
                    var curIndex = "face_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }

        for(var i=1;i<=17;i++)
        {
            cc.loader.loadRes("sound/chat/0/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "female_chat_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/chat/1/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "male_chat_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }
    },

    closeBetBtn:function(){
        console.log("按钮隐藏")
        for(var i=0;i<5;i++)
            this.betBtnList[i].active = false;
    },

    openBetBtn:function(){
        console.log("按钮显示")
        for(var i=0;i<5;i++)
            this.betBtnList[i].active = true;
    },

    updateMeScore:function(score){
        this.mainPlayerScore.string = Math.round(parseInt(score));
    },

    initBankerRun:function(){
        this.bankerAniLayer = this.node.getChildByName("bankerAniLayer");
        this.bankerInfo = this.bankerAniLayer.getChildByName("text");
        this.bankerAniLayer.active = true;
        this.bankerAniMask = this.bankerAniLayer.getChildByName("mask");
        this.bankerAniSchedule = -1;
        this.bankerRunList = [];
        this.bankerRunBegin = -1;
        this.bankerRunEnd = -1;
        this.bankerBoxList = [];
        for(var i=0;i<9;i++){
            this.bankerBoxList[i] = this.bankerAniLayer.getChildByName("userBgRob"+i);
            this.bankerBoxList[i].active = true;
            this.bankerBoxList[i].opacity = 0;
        }
    },
    resetBankerRun:function(){
        this.bankerRunList = [];
        this.bankerRunBegin = -1;
        this.bankerRunEnd = -1;
        this.bankerAniSchedule = -1;
        this.bankerAniMask.active = false;
    },
    hideBankerAni:function(){
        for(var i=0;i<9;i++)
            this.bankerBoxList[i].opacity = 0;
    },
    runBankerAni:function(endChair,cb){
        if(this.bankerRunList.length <= 1)
        {
            this.showBankerAfterAni();
            this.resetBankerRun();
            return;
        }
        window.DKTools.audioEG.playEffect("tips_BankerAni");
        this.bankerAniMask.active = true;
        this.bankerRunList.sort();
        this.bankerEndChair = endChair;
        this.bankerEndIndex = this.bankerRunList.indexOf(endChair);
        console.log("@@@@@runBankerAni@@@@@");
        console.log(this.bankerRunList);
        console.log("this.bankerEndChair==="+endChair);
        console.log("this.bankerEndIndex==="+this.bankerEndIndex);
        var moveStep = 6+parseInt(Math.random()*6)
        this.bankerBeginIndex = (this.bankerEndIndex + this.bankerRunList.length - (moveStep%this.bankerRunList.length - 1))%this.bankerRunList.length;
        console.log("bankerBeginIndex === ",this.bankerBeginIndex);
        var curStep = 0;
        var self = this;
        var callFunc = function(){
            self.bankerInfo.active = true
            self.bankerInfo.getComponent(cc.Label).string = self.bankerEndChair
            var callFunc1 = function(){
                self.bankerInfo.active = false
            }
            self.scheduleOnce(callFunc1,1)
        }
        this.bankerAniSchedule = function(){
            var curAniChair = self.bankerRunList[(this.bankerBeginIndex+curStep)%this.bankerRunList.length];
            curStep ++;
            if(self.bankerBoxList[curAniChair])
            {
                self.bankerBoxList[curAniChair].stopAllActions();
                self.bankerBoxList[curAniChair].opacity = 0;
                self.bankerBoxList[curAniChair].runAction(cc.sequence(cc.fadeIn(0.2),cc.fadeOut(0.2)));
            }
            if(curStep > moveStep)
            {
                window.DKTools.audioEG.playEffect("tips_BankerAniStop");
                console.log("curStep > moveStep");
                // self.unschedule(self.bankerAniSchedule);
                window.protectedUnschedule(self,self.bankerAniSchedule);
                self.bankerBoxList[endChair].stopAllActions();
                self.bankerBoxList[endChair].opacity = 255;
                self.showBankerAfterAni();
                callFunc()
                self.resetBankerRun();
            }
        };
        this.schedule(this.bankerAniSchedule,0.15,moveStep);
        this.bankerAniSchedule();
    },
});